//
//  XLCryptoTool+JFCloundChat.m
//  JFCloundChat
//
//  Created by ilongge on 2021/12/2.
//

#define AesEncryptKey  @"S8N30osxIL3xRMVW"
#define AesIvKey       @"Es8bKd8s0Sk3a0GX"

#import "XLCryptoTool+JFCloudChat.h"
#import <GTMBase64/GTMBase64.h>

@implementation XLCryptoTool (JFCloudChat)
/**
 * AES加密_Police
 * @param encryptData  需要加密的二进制数据
 */
+ (NSData *)cloudChatEncryptWithData:(NSData *)encryptData
{
    if (encryptData.length == 0) {
        return nil;
    }
    NSData *resultData = [XLCryptoTool aesEncryptWithKey:AesEncryptKey
                                                andIvKey:AesIvKey
                                                 andMode:XL_AES_Crypto_Mode_CBC
                                                 andData:encryptData];
    return resultData;
}

/**
 * AES加密_Police
 * @param encryptText  需要加密的字符串
 */
+ (NSString *)cloudChatEncryptWithText:(NSString *)encryptText
{
    if (encryptText.length == 0) {
        return nil;
    }
    
    NSString *resultString = [XLCryptoTool aesEncryptWithKey:AesEncryptKey
                                                    andIvKey:AesIvKey
                                                     andMode:XL_AES_Crypto_Mode_CBC
                                                     andText:encryptText];
    return resultString;
}

/**
 * AES解密_Police
 * @param decryptData  需要解密的二进制数据
 */
+ (NSData *)cloudChatDecryptWithData:(NSData *)decryptData
{
    if (decryptData.length == 0) {
        return nil;
    }
    NSData *resultData = [XLCryptoTool aesDecryptWithKey:AesEncryptKey
                                                andIvKey:AesIvKey
                                                 andMode:XL_AES_Crypto_Mode_CBC
                                                 andData:decryptData];
    return resultData;
}

/**
 * AES解密_Police
 * @param decryptText  需要解密的字符串
 */
+ (NSString *)cloudChatDecryptWithText:(NSString *)decryptText
{
    if (decryptText.length == 0) {
        return nil;
    }
    NSString *resultString = [XLCryptoTool aesDecryptWithKey:AesEncryptKey
                                          andIvKey:AesIvKey
                                           andMode:XL_AES_Crypto_Mode_CBC
                                           andText:decryptText];
    return resultString;
}
/**
 * BASE64编码_JFCloundChat
 * @param encodeText  需要编码的字符串
 */
+ (NSString *)base64Decode:(NSString *)decodeText
{
    NSData *decodeTextData = [GTMBase64 decodeString:decodeText];
    NSString *base64String = [[NSString alloc] initWithData:decodeTextData encoding:NSUTF8StringEncoding];
    return base64String;
}
/**
 * BASE64解码_JFCloundChat
 * @param encodeText  需要解码的字符串
 */
+ (NSString *)base64Encode:(NSString *)encodeText
{
    NSData *encodeTextData = [encodeText dataUsingEncoding:NSUTF8StringEncoding];
    NSString *base64String = [GTMBase64 stringByEncodingData:encodeTextData];
    return base64String;
}
@end
